package com.cn.trip.servlet;

import com.cn.trip.bean.Cart;
import com.cn.trip.bean.User;
import com.cn.trip.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Servlet implementation class GotoCheckOutServlet
 */
@WebServlet("/GotoCheckOut")
public class GotoCheckOutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GotoCheckOutServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		User user=(User)request.getSession().getAttribute("user");
		if(user.getCart()!=null) {
			CartService cs=new CartService();
			List<Cart> list=cs.getCartList(user.getId());
			request.setAttribute("cart", list);
			request.getRequestDispatcher("/checkOut.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("/bound.jsp").forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
